/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.service;

import java.util.Calendar;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.expert.dao.SystemDefinitionAreaSeasonDao;
import com.chlitina.store.modules.expert.entity.SystemDefinitionAreaSeason;

/**
 * 区域季节Service
 * @author lvbo
 * @version 2013-07-02
 */
@Component
@Transactional(readOnly = true)
public class SystemDefinitionAreaSeasonService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(SystemDefinitionAreaSeasonService.class);
	
	@Autowired
	private SystemDefinitionAreaSeasonDao systemDefinitionAreaSeasonDao;
	
	public SystemDefinitionAreaSeason get(Long id) {
		return systemDefinitionAreaSeasonDao.findOne(id);
	}
	
	public Page<SystemDefinitionAreaSeason> find(Page<SystemDefinitionAreaSeason> page, SystemDefinitionAreaSeason systemDefinitionAreaSeason) {
		DetachedCriteria dc = systemDefinitionAreaSeasonDao.createDetachedCriteria();
		dc.addOrder(Order.desc("id"));
		return systemDefinitionAreaSeasonDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(SystemDefinitionAreaSeason systemDefinitionAreaSeason) {
		systemDefinitionAreaSeasonDao.save(systemDefinitionAreaSeason);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		systemDefinitionAreaSeasonDao.delete(id);
	}
	
	public Long getTodayByArea(Long areaId) {
		Calendar cal = Calendar.getInstance();
		List<SystemDefinitionAreaSeason> item = systemDefinitionAreaSeasonDao.getTodayByArea(areaId, (long)cal.get(Calendar.MONTH) + 1);
		if(item.size() == 0) {
			return null;
		}
		return item.get(0).getId();
	}
}
